﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using DevicesInt;
using System.Resources;

namespace izmer_bizss
{
    public class BizssController : DeviceControl
    {

        public string IpAddress { get; set; }
        public static CultureInfo MyCurrentCulture { get; set; }

        public BizssController(string ip)
        {
            IpAddress = ip;
        }

        public override ControlType GetControlType
        {
            get { return ControlType.Control; }
        }

        public override object GetControl(CultureInfo cultureInfo = null)
        {
            return new ParametersControl(this, cultureInfo);
        }

        public override string ShowControl()
        {
            return Errors.NOT_IMPLEMENTED;
        }

        public override List<ParamInfo> GetParametersList()
        {
            const int cSattelites = 0;
            const int qSignal = 1;
            const int date = 2;
            const int etalon = 3;
            const int norma = 4;
            const int interval = 5;
            const int comp = 6;

            var strPars = GetParametersString();
            if (strPars.StartsWith("err:"))
                throw new Exception(strPars.Remove(0, 4));
            var parString = strPars.Split(new[] {';'}, StringSplitOptions.RemoveEmptyEntries);
            var parList = new List<ParamInfo>(parString.Count());
            int i = 0;
            foreach (var s in parString)
            {
                var p = new ParamInfo();
                switch (i++)
                {
                    case cSattelites:
                        //p.StringFormat = @"[0-9]{1-2}";
                        p.Name = 
                        p.Value = s;
                        break;
                    case qSignal:
                        p.StringFormat = @"[0-9]{1}";
                        break;
                    case date:
                        break;
                    case etalon:
                        p.CanSet = true;
                        break;
                    case norma:
                        p.CanSet = true;
                        break;
                    case interval:
                        break;
                    case comp:
                        break;
                }
                
                var split = s.Split(':');
                p.Name = split[0];
                p.Value = split[1];
                parList.Add(p);
            }
            return parList;
        }

        public override string GetParametersString()
        {
            return BIZSS.Getparams(IpAddress);
        }

        public override string SetParameter(string paramValue, string paramName = null)
        {
            return BIZSS.Setparams(IpAddress, paramValue);
        }
    }
}
